﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using Schematrix;
using VMDS.Business.Processes;
using VMDS.Data;

namespace Teleportator
{
    class Program
    {

        static void end()
        {
            Console.ReadLine();
            Environment.Exit(0);
        }

        static void Main(string[] args)
        {
            string Source = @"\\study.rsvpu.ru\FI\Virtual";
            string Destination = @"d:\virtual\!share\update";
            string Setup= Destination+"\\setup.exe";
            if (!File.Exists(Setup))
            { 
                Console.WriteLine("setup.exe not found");
                end();
            }
            FileVersionInfo info = FileVersionInfo.GetVersionInfo(Setup);
            var vsetup = info.ProductVersion;
            var myvers = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            var needupd = myvers != vsetup;
            Console.WriteLine(vsetup+"\n"+myvers+"\n"+needupd);

            end();

        }

        static void extract(string rar,string dest)
        {
            // Get hashtable of selected files
            var unrar=new Unrar();
            unrar.ExtractionProgress += new ExtractionProgressHandler(unrar_ExtractionProgress);
            //try
            //{
            //    // Get destination from user
                   
                   
                    // Set destination path for all files
                var c = '\'';
            
            Console.WriteLine();
            unrar.DestinationPath = dest;

                    // Open archive for extraction
                    unrar.Open(rar, Unrar.OpenMode.Extract);

                    // Extract each file found in hashtable
                    while (unrar.ReadHeader())
                    {
                            unrar.Extract();
                        
                    }
                
            //}
            //catch (Exception ex)
            //{
            //   Console.WriteLine(ex);
            //}
            //finally
            //{
            //    if (unrar != null)
            //        unrar.Close();
            //}
        }

        static void unrar_ExtractionProgress(object sender, ExtractionProgressEventArgs e)
        {
            var x = Console.CursorLeft;
            var y = Console.CursorTop;
            Console.Write("Extracting " + e.PercentComplete.ToString("f1") + "%");
            Console.SetCursorPosition(x, y);
        }



        static void copier_CopyProgress(object sender, CopyProgressEventArgs e)
        {
            var p=(int)(e.TotalBytesTransferred * 100 / e.TotalFileSize);
            var x = Console.CursorLeft;
            var y = Console.CursorTop;
            Console.Write("Copying "+p+"%");
            Console.SetCursorPosition(x,y);
        }
    }
}
